#include "CStateManagement.h"

namespace GameTutor
{
	CStateManagement* CStateManagement::s_pInstance = 0;

	void CStateManagement::Update(bool isPause)
	{
		// check if need switch state
		if (m_pcurrentSate != m_pnextState)
		{
			if (m_pcurrentSate)
			{
				m_pcurrentSate->Exit();
				delete m_pcurrentSate;
			}
			if (m_pnextState)
			{
				m_pnextState->Init();
			}
			m_pcurrentSate = m_pnextState;
		}

		// update state
		if (m_pcurrentSate)
		{
			if (!isPause)
			{
				m_pcurrentSate->Update();
			}
			m_pcurrentSate->Render();
		}
	}

	void CStateManagement::SwitchState(CState* next)
	{
		m_pnextState = next;
	}
}